<!--
  @Description:发布成果
  @author Wangshu
  @date 2019/8/22
-->

<!doctype html>
<html lang="en">
<head>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link rel="stylesheet" href="__PUBLIC__/css/common/bootstrap.min.css">
    <link rel="stylesheet" href="__PUBLIC__/css/header.css">
    <link rel="stylesheet" href="__PUBLIC__/css/changeData.css">
    <link rel="stylesheet" href="__PUBLIC__/css/menu.css">
    <link rel="stylesheet" href="__PUBLIC__/css/common/common.css">
    <script type="text/javascript" src="__STATIC__/layui/layui.all.js"></script>
    <title>山东科技大学技术转移公共服务平台-发布成果</title>
</head>
<body>
<head>
    <div class="top-title">
        <div>
            <span>欢迎登陆山东科技大学技术转移公共服务平台！</span>
            <if condition="$uid eq null">
                <div class="login">
                    <img src="__PUBLIC__/asset/icon/people.png" alt="">
                    <a href="{:url('login/index')}">登录</a>
                    <span class="spece">|</span>
                    <a href="{:url('login/signup')}">注册</a>
                </div>
                <else/>
                <div class="login">
                    <img src="__PUBLIC__/asset/icon/people.png" alt="">
                    <a href="{:url('me/me')}">欢迎你！</a>
                    <a href="{:url('me/me')}">{$user.real_name}</a>
                </div>
            </if>
        </div>
    </div>
    <div class="logo-box">
        <div class="logo-wrap">
            <div>
                <img src="__PUBLIC__/asset/fodder/logo.png" alt="">
            </div>
            <div>
                <div class="search">
                    <div class="dropdown">
                        <div class="btn select-default dropdown-toggle" type="button" id="dropdownMenu1"
                             data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
                            请选择学院
                            <span><img style="width: 20px;" src="__PUBLIC__/asset/icon/dropdown.png" alt=""></span>
                        </div>
                        <ul class="dropdown-menu" aria-labelledby="dropdownMenu1">
                            <foreach name="allColleges" item="vo">
                                <li><a onclick="shows1($(this).text(),{$vo.id})">{$vo.college_name}</a></li>
                            </foreach>
                        </ul>
                    </div>
                    <div class="search-block">
                        <input type="text" name="keyword" id="keyword">
                    </div>
                    <div class="submit" id="submit">
                        <img src="__PUBLIC__/asset/icon/search.png" alt="">
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="nav-box">
        <div class="nav-list">
            <ul>
                <li><a href="{:url('/index/index')}">首页</a></li>
                <li><a href="{:url('news/index')}">新闻</a></li>
                <li><a href="{:url('people/index')}">人才库</a></li>
                <li><a href="{:url('fruit/index')}">成果库</a></li>
                <if condition="$user_type eq 0">
                <li><a href="{:url('requirement/index')}">需求库</a></li>
                </if>
                <li class="active"><a href="{:url('me/callme')}">联系我们</a></li>
            </ul>
        </div>
    </div>
</head>
<main>
    <div class="content-wrap">
        <div class="menu-left">
            <div class="title">个人中心</div>
            <ul>
                <li>
                    <a href="{:url('me/me')}">个人资料</a>
                    <img src="__PUBLIC__/asset/icon/right_arrow.png" alt="">
                </li>
                <li class="active"><a href="{:url('me/fruit')}">我发布的成果</a><img class="active-arrow"
                                                                             src="__PUBLIC__/asset/icon/right_arrow.png" alt="">
                </li>
                <li><a href="{:url('me/requirement')}">我发布的需求</a><img src="__PUBLIC__/asset/icon/right_arrow.png" alt=""></li>
                <li><a href="{:url('me/team')}">我的团队</a><img src="__PUBLIC__/asset/icon/right_arrow.png" alt=""></li>
                <li><a href="{:url('me/collection')}">我的收藏</a><img src="__PUBLIC__/asset/icon/right_arrow.png" alt=""></li>
                <li><a href="{:url('me/FAQ')}">常见问题</a><img src="__PUBLIC__/asset/icon/right_arrow.png" alt=""></li>
                <li><a href="{:url('me/callMe')}">联系客服</a><img src="__PUBLIC__/asset/icon/right_arrow.png" alt=""></li>
                <li><a href="{:url('me/other')}">其他设置</a><img src="__PUBLIC__/asset/icon/right_arrow.png" alt=""></li>
            </ul>
        </div>
        <div class="menu-right">
            <div class="title">
                <div>发布成果</div>
                <div>当前位置：<span>个人中心/我发布的成果/发布成果</span></div>
            </div>
            <div class="content">
                <form class="layui-form" id="userForm" lay-filter="deptForm" enctype="multipart/form-data">
                    <input type="hidden" name="id" value="{$fruit.id}">
                <div class="option">
                    <div>标题：</div>
                    <div class="text-box"><input type="text" id="title" name="title" placeholder="请输入标题" value="{$fruit.title}" required></div>
                </div>
                <div class="option">
                    <div>关键词：</div>
                    <div class="text-box"><input type="text" id="keywords" name="keywords" placeholder="请输入关键词" value="{$fruit.keywords}"></div>
                </div>

                    <div class="option">
                        <div>成果类型：</div>
                        <div class="dropdown">
                            <button class="btn btn-default dropdown-toggle" type="button" id="dropdownMenu2"
                                    data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
                                <span id="fruitTypeSel">{$fruit.fruit_type.name|default="请选择类型"}</span>
                                <span><img style="width: 20px;" src="__PUBLIC__/asset/icon/dropdown.png" alt=""></span>
                            </button>
                            <ul class="dropdown-menu" aria-labelledby="dropdownMenu1">
                                <foreach name="fruit_type" item="vo">
                                    <li><a onclick="selectType($(this).text(),{$vo.id})">{$vo.name}</a></li>
                                </foreach>
                            </ul>
                            <input type="hidden" name="type" id="type" value="{$fruit.type}" required>
                        </div>
                    </div>

                <div class="option">
                    <div>附件：</div>
                    <div class="text-box upfile">
                        <div>
                            <label>上传附件</label>
                            <input type="file" name="file" id="file" accept="application/msword,application/xml-dtd,application/pdf,application/vnd.ms-powerpoint,application/vnd.ms-works">
                        </div>
                        <div class="del" onclick="deleteFile()">删除</div>
                        <span id="fileNameContainer">
                             <if condition="$fruit.file_name neq null">
                            <p id="fileName">{$fruit.file_name}</p>
                        </if>
                        </span>
                    </div>

                </div>
                <div class="option">
                    <div>内容：</div>
                    <script id="container" name="content" type="text/plain">
                        {$fruit.content|raw}
                    </script>
                </div>
                <div class="save top">
                    <div id="save">保存</div>
                    <!--<button id="get" lay-filter="reg" class="layui-btn btn-submit"  type="button" lay-submit="">立即注册</button>-->
                </div>
                </form>
            </div>

        </div>
    </div>
</main>
<footer>
    <div class="foot-line">
        <span>青岛校区地址：山东省青岛市黄岛区前湾港路579号</span>
        <span>邮政编码：266590</span>
        <span>联系电话：0532-80698028\80698027\80678029</span>
        <span>传真：0532-80698029</span>
    </div>
    <div class="foot-line">
        <span>泰安校区地址：山东省泰安市岱宗大街223号</span>
        <span>邮政编码：271019</span>
        <span>联系电话：0538-3076489</span>
        <span>传真：0538-3076489</span>
    </div>
    <div class="last-line">
        Copyright©2019 　山东科技大学 　鲁ICP备09051012号
        <span style="line-height: 26px ; margin-left: 20px;"><img
                style="width: 44px;height: 17px; margin-right: 10px;vertical-align: middle"
                src="__PUBLIC__/asset/fodder/todo_white.png" alt=""><span
                style="vertical-align: middle">投道科技提供技术支持</span></span>
    </div>
</footer>
<div class="pop-box">
    <div class="pop">
        <img class="close" src="__PUBLIC__/asset/icon/close.png" alt="">
        <div class="logo"><img src="__PUBLIC__/asset/icon/success.png" alt=""></div>
        <p id="popText">您的个人资料保存成功</p>
        <div class="affirm">
            <div id="affirmBtn">确定</div>
        </div>
    </div>
</div>
<script src="__PUBLIC__/js/public/jquery-1.11.3.min.js"></script>
<script src="__PUBLIC__/js/public/bootstrap.min.js"></script>
<script src="__PUBLIC__/js/layer/layer/layer.js"></script>

<!-- 配置文件 -->
<script type="text/javascript" src="__STATIC__/ueditor/ueditor.config.js"></script>
<!-- 编辑器源码文件 -->
<script type="text/javascript" src="__STATIC__/ueditor/ueditor.all.js"></script>
<!-- 实例化编辑器 -->
<script type="text/javascript">
    var ue = UE.getEditor('container', {
        toolbars: [
            [
                'undo', //撤销
                'bold', //加粗
                'underline', //下划线
                'preview', //预览
                'horizontal', //分隔线
                'inserttitle', //插入标题
                'cleardoc', //清空文档
                'fontfamily', //字体
                'fontsize', //字号
                'paragraph', //段落格式
                'simpleupload', //单图上传
                'insertimage', //多图上传
                'attachment', //附件
                'music', //音乐
                'inserttable', //插入表格
                'emotion', //表情
                'insertvideo', //视频
                'justifyleft', //居左对齐
                'justifyright', //居右对齐
                'justifycenter', //居中对
                'justifyjustify', //两端对齐
                'forecolor', //字体颜色
                'fullscreen', //全屏
                'edittip ', //编辑提示
                'customstyle', //自定义标题
                'template', //模板
            ]
        ]
    });
</script>

<script>
    $('#save').on('click', function () {

        var formData = new FormData($( "#userForm" )[0]);

        if (document.getElementById('file').files[0]) {
            var size = document.getElementById('file').files[0].size;
            var filesize = (size / 1024).toFixed(2);
            if(filesize > 10 * 1024){
                return layer.msg('文件上传最大支持10M',{
                    time:1500
                })
            }
        }
        var index = layer.load(1);

        $.ajax({
            cache : true,
            type : "post",
            url : "save",
            async : true,
            data : formData,  // 你的formid
            contentType: false,   //jax 中 contentType 设置为 false 是为了避免 JQuery 对其操作，从而失去分界符，而使服务器不能正常解析文件
            processData: false,   //当设置为true的时候,jquery ajax 提交的时候不会序列化 data，而是直接使用data
            error : function(request) {
                layer.alert('操作失败', {
                    icon: 2,
                    title:"提示"
                });
            },
            success : function(ret) {
                if (ret.code == 0) {
                    layer.alert(ret.msg, {
                        icon: 2,
                        title:"提示"
                    });
                } else {
                    layer.alert(ret.msg, {
                        icon: 1,
                        title:"提示"
                    },function (index) {
                        layer.close(index)
                        window.location.reload();
                    });
                }
                layer.close(index);
            }
        })
    });

    $('#update').on('click', function () {
        $('.pop-box').css('display', 'block')
        $('#popText').text('您在人才库更新成功！')
    })

    $('#affirmBtn').on('click', function () {
        $('.pop-box').css('display', 'none')
    })

    $('.close').click(function () {
        $('.pop-box').css('display', 'none')
    })

    $(".tag-box ul li").click(function () {
        let status = $(this).hasClass("active")
        if (status === false) {
            $(this).addClass('active')
        } else {
            $(this).removeClass('active')
        }
    });
    $('.dropdown-toggle').dropdown()

    var selectCollege = null;
    function shows1(a,id) {
        selectCollege = {id,college:a};
        $("#dropdownMenu1").text(a);
    }


    $("#submit").on('click',function () {
        var name = $("#keyword").val();
        if(!selectCollege){
            window.open("{:url('fruit/index')}?keyword="+name)
        }else{
            window.open("{:url('fruit/index')}?college="+selectCollege.id+"&keyword="+name)
        }
    })

    function deleteFile() {
        if (!document.getElementById('file').files[0] && !!`{$fruit.attachment}`){
            layer.confirm('确认删除该文件?', {icon: 3, title:'提示'}, function(index){
                //do something
                layer.close(index);

                $.post("{:url('deleteFile')}",{id:`{$fruit.id}`}, function (ret) {
                    $("#fileName").remove();
                    var file = $("#file")
                    file.after(file.clone().val(""));
                    file.remove();
                    return layer.msg(ret.msg)
                })
            });

        }else{
            $("#fileName").remove();
            var file = $("#file")
            file.after(file.clone().val(""));
            file.remove();

            $("#file").change(function (e) {
                var name = e.currentTarget.files[0].name;
                console.log(name)
                $("#fileName").remove();
                $("#fileNameContainer").append(`<p id="fileName">${name}</p>`);
            })
        }
    }

    $("#file").change(function (e) {
        var name = e.currentTarget.files[0].name;
        console.log(name)
        $("#fileName").remove();
        $("#fileNameContainer").append(`<p id="fileName">${name}</p>`);
    })

    function selectType(name,id) {
        $("#fruitTypeSel").text(name)
        $("#type").val(id)
    }
</script>

</body>
</html>

